<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增申请')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-apply-add">
        <div class="form-group">
            <label class="col-sm-2 control-label">标题：</label>
            <div class="col-sm-10">
                <input id="title" name="title" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">申请人：</label>
            <div class="col-sm-10">
                <input id="applicant" name="applicant" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">内容：</label>
            <div class="col-sm-10">
                <textarea id="content" class="form-control" rows="6" name="content"></textarea>
            </div>
        </div>
        <!--<div class="col-sm-6">-->
            <!--<div class="form-group">-->
                <!--<label class="col-sm-4 control-label">状态：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<label class="toggle-switch switch-solid">-->
                        <!--<input type="checkbox" id="status" checked>-->
                        <!--<span></span>-->
                    <!--</label>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-2 control-label">附件：</label>
            <div class="col-sm-10">
                <input id="filePath" name="file" type="file" multiple class="file-upload form-control " />
            </div>
        </div>
    </form>
</div>
<!--<div class="row">-->
    <!--<div class="col-sm-offset-5 col-sm-10">-->
        <!--<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;-->
        <!--<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>-->
    <!--</div>-->
<!--</div>-->
<th:block th:include="include :: footer" />
<th:block th:include="include :: summernote-js" />
<script type="text/javascript">
    var prefix = ctx + "zzuser/apply";
    var fileName="";
    var url="";
    var file="";

    // function submitHandler() {
    //     if ($.validate.form()) {
    //         var data = $("#form-apply-add").serializeArray();
    //         var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
    //         var roleIds = $.form.selectCheckeds("role");
    //         var postIds = $.form.selectSelects("post");
    //         data.push({"name": "status", "value": status});
    //         data.push({"name": "roleIds", "value": roleIds});
    //         data.push({"name": "postIds", "value": postIds});
    //         $.operate.saveTab(prefix + "/add", data);
    //     }
    // }
    function submitHandler() {
        var val = $("#form-apply-add").serialize();
        console.log(val);
        if ($.validate.form()) {
            uploadFile();

            var fromData = $("#form-apply-add").serialize();

            $.operate.save(prefix + "/add/submit",fromData+"&fileName="+file+"&url="+url);
        }
    }


    //文件上传
    function uploadFile() {
        var formData = new FormData();
        if ($('#filePath')[0].files[0]==null) {
            return false;
        }
        file = $('#filePath')[0].files[0].name;
        formData.append('fileName', $("#filePath").val());
        formData.append('file', $('#filePath')[0].files[0]);
        $.ajax({
            url: ctx + "common/upload",
            type: 'post',
            cache: false,
            data: formData,
            async:false,    //同步
            processData: false,
            contentType: false,
            dataType: "json",
            success: function(result) {
                fileName = result.fileName;
                url = result.url;
                if(result){
                    parent.$.modal.msgSuccess(result.msg);
                }
            }
        });
    }

</script>
</body>
</html>
